package com.android.mios;

import com.android.mios.adapter.GalleryFunctionAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

import android.widget.Gallery;
import android.widget.LinearLayout;

public class SystemSettingActivity extends AbstractMyActivityGroup implements
		OnItemClickListener, OnItemSelectedListener {

	private static final String SYSTEM_EDIT_ALLDEVICE_ACTIVITY = "SystemEditAllDeviceActivity";
	private static final String SYSTEM_SWITCH_SKIN_ACTIVITY = "SystemSwitchSkinActivity";
	private GalleryFunctionAdapter mGalleryFunctionAdapter;

	private Gallery gallery_function;
	private LinearLayout setting_container;
	private String[] arrayOfFunction = new String[2];

	private final static int TOOLBAR_ITEM_Edit_DEVICE = 0;
	private final static int TOOLBAR_SWITCH_SKIN_DEVICE = 1;

	private int iPosition = -1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.system_setting_layout);
		initData();
		initView();

	}

	private void initData() {

		// res = getResources();
		arrayOfFunction[0]= getString(R.string.edit_device_list);
		arrayOfFunction[1]= getString(R.string.change_skin);
		

		mGalleryFunctionAdapter = new GalleryFunctionAdapter(this,
				arrayOfFunction);

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub

		super.onResume();

	}

	private void initView() {

		gallery_function = (Gallery) findViewById(R.id.galery_funtion);
		gallery_function.setAdapter(mGalleryFunctionAdapter);
		// gallery_function.setOnItemClickListener(this);
		gallery_function.setOnItemSelectedListener(this);

		setting_container = (LinearLayout) findViewById(R.id.setting_container);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long arg3) {
		// changeActivity(position);

	}

	private void changeActivity(int position) {

		if (position == TOOLBAR_ITEM_Edit_DEVICE) {
			if (iPosition != TOOLBAR_ITEM_Edit_DEVICE) {
				setContainerView(SYSTEM_EDIT_ALLDEVICE_ACTIVITY,
						SystemEditAllDeviceActivity.class);
				iPosition = TOOLBAR_ITEM_Edit_DEVICE;
			}
		} else if (position == TOOLBAR_SWITCH_SKIN_DEVICE) {
			if (iPosition != TOOLBAR_SWITCH_SKIN_DEVICE) {
				setContainerView(SYSTEM_SWITCH_SKIN_ACTIVITY,
						SystemSwitchSkinActivity.class);
				iPosition = TOOLBAR_SWITCH_SKIN_DEVICE;
			}
		}

	}

	@Override
	protected LinearLayout getContainer() {
		// TODO Auto-generated method stub
		return (LinearLayout) findViewById(R.id.setting_container);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);
		SystemSwitchSkinActivity systemSwitchSkinActivity = (SystemSwitchSkinActivity) getLocalActivityManager()
				.getCurrentActivity();
		systemSwitchSkinActivity.handleOnActivityResult(requestCode,
				resultCode, data);
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position,
			long id) {
		changeActivity(position);
		setting_container.setAnimation(AnimationUtils.loadAnimation(this,
				R.anim.fade));
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub

	}

}
